// CancelAssign_Servlet.java
package SaveServlet.manager;

import com.lyq.bean.mySql.ElectC_Sql;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/cancelAssign")
public class CancelAssign_Servlet extends HttpServlet {


    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("application/json;charset=UTF-8");
        response.setCharacterEncoding("UTF-8");
        PrintWriter out = response.getWriter();
        
        try {
            String courseId = request.getParameter("courseId");

            // 取消分配
            boolean result = new ElectC_Sql().cancelCourseAssignment(courseId);
            
            if (result) {
                out.print("{\"success\": true, \"message\": \"取消分配成功\"}");
            } else {
                out.print("{\"success\": false, \"message\": \"取消分配失败\"}");
            }
        } catch (Exception e) {
            e.printStackTrace();
            out.print("{\"success\": false, \"message\": \"取消分配异常: " + e.getMessage() + "\"}");
        }
    }
}